package com.alex.server.service.impl;


import com.alex.server.pojo.AdminRole;
import com.alex.server.pojo.RespBean;
import com.alex.server.service.IAdminRoleService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.alex.server.mapper.AdminRoleMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * <p>
 * 管理员角色中间表 服务实现类
 * </p>
 *
 * @author alex
 * @since 2022-08-30
 */
@Service
public class AdminRoleServiceImpl extends ServiceImpl<AdminRoleMapper, AdminRole> implements IAdminRoleService {
    @Autowired
    public AdminRoleMapper adminRoleMapper;
    @Transactional
    @Override
    public RespBean updateRole(Integer adminId, Integer[] rids) {
        adminRoleMapper.delete(new QueryWrapper<AdminRole>().eq("adminId",adminId));
        if (rids.length==0||rids==null){
            return RespBean.success("更新成功");
        }
        Integer result = adminRoleMapper.updateRole(adminId, rids);
        if (result==rids.length) {
            return RespBean.success("更新成功");
        }else {
            return RespBean.error("更新失败");
        }
    }
}
